﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

public class LevelSelect : MonoBehaviour
{
    public GameObject bg;
    public GameObject scene_select;
    public GameObject back_button;
    public List<GameObject> scenes;
    private string a;
    private int max_num = 5; //每个场景的最高关卡数
    public int[] star_k = new int[6];
    private int temp_num;

    private void Awake()
    {
        for (int i = 1;i <= 3;i++)
        {
            star_k[i] = 0;
            for (int j = 1; j <= max_num;j++)
            {
                temp_num = PlayerPrefs.GetInt("level" + i.ToString() + "-" + j.ToString(), 0);
                star_k[0] += temp_num;
                star_k[i] += temp_num;
            }
        }
    }

    public void ClickScene()  //选择场景
    {
        a = EventSystem.current.currentSelectedGameObject.name;  //取得被点击对象的名字
        a = a.Split('-')[1];  //获取名字最后的数字
        PlayerPrefs.SetString("now_scene",a);
        scene_select.SetActive(false);
        back_button.SetActive(true);
        scenes[int.Parse(a)-1].SetActive(true);
    }

    public void ClickNumber()  //选择关卡
    {
        a = EventSystem.current.currentSelectedGameObject.name;
        PlayerPrefs.SetString("now_number", a);
        SceneManager.LoadScene(2);
    }

    public void GoBack()  //返回按钮
    {
        PlayerPrefs.GetString("now_scene", a);
        scenes[int.Parse(a) - 1].SetActive(false);
        back_button.SetActive(false);
        scene_select.SetActive(true);
    }

    //选择场景界面的背景切换
    public void GetBackground(GameObject other_bg)
    {
        bg.SetActive(false);
        bg = other_bg;
        bg.SetActive(true);
    }
}
